//
//  UIImageView+WebImage.swift
//  weibo
//
//  Created by apple on 2017/7/11.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

import SDWebImage
extension UIImageView{
    
    /// 隔离sdwebimage 设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: urlstring
    ///   - placeholderImage: 占位图像
    /// - isavatar :是否是头像
    func  hbj_setImage(urlString:String?,placeholderImage:String?,isAvatar: Bool = false){
        
    guard let urlstring = urlString,
        let url = URL(string: urlstring) else {
            return
        }
        //let placeImgeString = placeholderImage
        let placehoderImage = UIImage(named: placeholderImage ?? "")
        
        sd_setImage(with: url, placeholderImage: placehoderImage, options: [], progress: nil) { (image , _ , _ , _) in
            //完成回调 - 判断是否是头像
            if isAvatar {
               self.image = image?.hbj_AvatarIcon(image: image, size: self.bounds.size, backColor: UIColor.white)
            }
        }
    }
}
